package es.iespuertodelacruz.dai.batallanaval.gui;

import javax.swing.JDialog;
import javax.swing.JSeparator;
import java.awt.Frame;

import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JToggleButton;

import java.awt.FlowLayout;


public class FleetDialog extends JDialog {
	
	ButtonGroup btnGroup = new ButtonGroup();
	
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = FleetDialog.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
	
	private void initialize(JPanel panelTop, JPanel panelBottom) {
		
		JToggleButton[] shipButtons = new JToggleButton[8];
		JToggleButton btn;
		ImageIcon imgIcon;

		for(int i = 0; i < 4; i++) {
			shipButtons[i] = btn = new JToggleButton();
			imgIcon = createImageIcon("/img/hship"+(i+1)+".png");
			btn.setIcon(imgIcon);
			btn.setActionCommand(String.valueOf(i));
			panelTop.add(btn);
			btnGroup.add(btn);
		}
	
		for(int i = 4; i < 8; i++) {
			shipButtons[i] = btn = new JToggleButton();
			imgIcon = createImageIcon("/img/vship"+(i-3)+".png");
			btn.setIcon(imgIcon);
			btn.setActionCommand(String.valueOf(i));
			panelBottom.add(btn);
			btnGroup.add(btn);			

		}
		pack();
	}
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 605754556316034201L;

	public FleetDialog(Frame owner) {
		super(owner);
		
		getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
		
		JPanel panelTop = new JPanel();
		getContentPane().add(panelTop);
		panelTop.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		JSeparator separator = new JSeparator();
		getContentPane().add(separator);
		
		JPanel panelBottom = new JPanel();
		getContentPane().add(panelBottom);
		panelBottom.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		initialize(panelTop, panelBottom);
	}

}
